package com.swift.maintenance.utils;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.swift.maintenance.R;

public class CheckUtil {

	public static boolean checkEditText(EditText... editTexts)
	{
		boolean result = true;
		
		for (EditText editText : editTexts) {
			if (TextUtils.isEmpty(editText.getText().toString())) {
				ToastUtil.getInstances().showMsg(editText.getTag(R.id.tag_view_empty).toString());
				editText.requestFocus();
				return false;
			}
		}
		
		return result;
	}
	
	/**   
	 * @author: HYM 
	 * @Title: checkView   
	 * @Description: TODO(检测必填输入提示)   
	 * @param: @param view
	 * @param: @return      
	 * @return: boolean    
	 * @return: 2017-5-5
	 * @throws   
	 */  
	public static boolean checkView(View... view)
	{
		boolean result = true;
		
		for (View mView: view) {
			if (mView instanceof EditText) {
				//判断是否输入框
				EditText editText = (EditText) mView;
				if (TextUtils.isEmpty(editText.getText().toString())) {
					ToastUtil.getInstances().showMsg(editText.getTag(R.id.tag_view_empty).toString());
					editText.requestFocus();
					return false;
				}
			}
			else if (mView instanceof Spinner) {
				//判断是否选择框
				Spinner spinner = (Spinner) mView;
				//判断其是否有选中的值，如果不存在就提示需要选择
				if(TextUtils.isEmpty(spinner.getTag(R.id.tag_view_select_value).toString()))
				{
					ToastUtil.getInstances().showMsg(spinner.getTag(R.id.tag_view_empty).toString());
					spinner.requestFocus();
					return false;
				}
			}
			else if (mView instanceof TextView){
				//判断是否输入框
				TextView textView = (TextView) mView;
				if (TextUtils.isEmpty(textView.getText().toString())) {
					ToastUtil.getInstances().showMsg(textView.getTag(R.id.tag_view_empty).toString());
					return false;
				}
			}
			
		}
		
		return result;
	}
}
